package main

import (
	"encoding/json"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/prometheus/common/model"
	"net/http"
	"time"
)

type OnlineTotal struct {
	OnlineTotal int `json:"onlineTotal"`
}

type responseInfo struct {
	Status bool        `json:"status"`
	Auth   bool        `json:"auth"`
	Code   string      `json:"code"`
	Res    OnlineTotal `json:"res"`
}

type Alert struct {
	model.Alert

	UpdatedAt time.Time
	Timeout   bool
}

func main() {
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		//panic("tets")
		c.JSON(http.StatusInternalServerError, "string")
	})
	r.GET("/vms", func(c *gin.Context) {
		c.JSON(http.StatusInternalServerError, responseInfo{
			Status: true,
			Auth:   true,
			Code:   "0",
			Res: OnlineTotal{
				OnlineTotal: 100,
			},
		})
	})

	r.POST("/api/v1/alerts", func(c *gin.Context) {
		//dec := json.NewDecoder(r.Body)
		//defer r.Body.Close()
		// 打印请求参数
		var alerts model.Alerts
		if err := c.ShouldBindJSON(&alerts); err != nil {
			panic(err)
		}

		jsonData, err := json.Marshal(alerts)
		if err != nil {
			fmt.Println("Error:", err)
			return
		}

		fmt.Println(string(jsonData))

		c.JSON(http.StatusInternalServerError, responseInfo{
			Status: true,
			Auth:   true,
			Code:   "0",
			Res: OnlineTotal{
				OnlineTotal: 100,
			},
		})
	})
	r.Run(":8080") // listen and serve on 0.0.0.0:8080
}
